<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="text" class="ipt1" />
    <input type="text" class="ipt2" />
    <button>点击显示水仙花数</button>
    <input type="text" class="ipt3" />
  </body>
</html>
<script>
  var oIpt1 = document.querySelector(".ipt1");
  var oIpt2 = document.querySelector(".ipt2");
  var oIpt3 = document.querySelector(".ipt3");
  var oBtn = document.querySelector("button");
  var str = "";
  oBtn.onclick = function () {
    if (oIpt1.value.trim() == "" || oIpt2.value.trim() == "")
      return alert("请输入内容");
    if (isNaN(oIpt1.value) || isNaN(oIpt2.value)) return alert("请输入数字");

    for (var i = oIpt1.value; i <= oIpt2.value; i++) {
      var g = i % 10;
      var s = parseInt((i / 10) % 10);
      var b = parseInt(i / 100);

      if (g * g * g + s * s * s + b * b * b == i) {
        str += i + " ";
      }
    }
    oIpt3.value = str;
  };
</script>
